import base64
import os


def pic2py(picture_name):
    """
    将图像文件转换为py文件
    :param picture_name:
    :return:
    """
    current_directory = os.path.dirname(os.path.abspath(__file__))
    open_pic = open(current_directory + "\\" + picture_name, 'rb')
    b64str = base64.b64encode(open_pic.read())
    open_pic.close()

    write_data = 'img = "%s"' % b64str.decode()
    file_name = picture_name.replace('.', '_') + ".py"
    f = open(current_directory + "\\" + file_name, 'w+')
    f.write(write_data)
    f.close()


if __name__ == '__main__':
    pics = [
        "config_click.png", "config.png", "order_click.png", "order.png",
        "trade_click.png", "trade.png"
    ]
    for i in pics:
        pic2py(i)
    print("ok")
